package com.ruoyi.order.Task;/**
 * @Author: liuzhuan
 * @Date: 2025/8/7 15:26
 * @Description: ToDo
 **/

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import co.elastic.clients.elasticsearch.ssl.ElasticsearchSslClient;
import com.ruoyi.order.domain.TbOrder;
import com.ruoyi.order.mapper.TbOrderMapper;
import com.ruoyi.order.service.ITbOrderService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author liuzhuan
 * @version 1.0
 * @description: TODO
 * @date 2025/8/7 15:26
 */
@Component
public class synOrderTask {


    @Autowired
    ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Autowired
    ITbOrderService tbOrderService;

    @PostConstruct
    public void synOrderEs(){
        System.out.println("开始实行任务");
        IndexOperations indexOps = elasticsearchRestTemplate.indexOps(TbOrder.class);
        boolean exists = indexOps.exists();
        if(!exists){
            indexOps.create();
            Document mapping = indexOps.createMapping();
            indexOps.putMapping(mapping);
        }
        TbOrder tbOrder = new TbOrder();
        List<TbOrder> list = tbOrderService.selectTbOrderList(tbOrder);
        for (TbOrder order : list) {
            elasticsearchRestTemplate.save(order);
        }

    }
}